package hu;

import java.sql.*;

public class Hu {
	public static final String DBDRIVER = "com.microsoft.sqlserver.jdbc.SQLServerDriver";
	public static final String DBURL = "jdbc:sqlserver://localhost:1433;databaseName=yonghu";
	public static final String DBUSER = "shuo";
	public static final String DBPASS = "shuo970826";
	Connection conn = null;
	Statement stmt = null;
	ResultSet rs = null;

	public void shuo() {
		try {
			Class.forName(DBDRIVER);
		} catch (ClassNotFoundException e) {
			e.printStackTrace();
		}
		try {
			conn = DriverManager.getConnection(DBURL, DBUSER, DBPASS);
			stmt = conn.createStatement();
		} catch (SQLException e) {

		}
	}

	public boolean tian(String a, String b, String c) {
		this.shuo();
		String sqlStr = "select ming from yonghu";
		try {
			rs = stmt.executeQuery(sqlStr);
			while (rs.next()) {
				String name = rs.getString(1);
				if (a.equals(name)) {
					return false;
				}

			}
			sqlStr = "insert into yonghu values('" + a + "','" + b + "','" + c
					+ "')";
			stmt.executeUpdate(sqlStr);
			return true;
		} catch (SQLException e) {

		}
		return false;

	}

	public boolean deng(String a, String b) {
		this.shuo();
		String sqlStr = "select ming,mima from yonghu";
		try {
			rs = stmt.executeQuery(sqlStr);
			while (rs.next()) {
				String name = rs.getString(1);
				String mima = rs.getString(2);
				if (name.equals(a) && mima.equals(b)) {
					return true;
				}
			}
			return false;
		} catch (SQLException e) {

		}
		return false;
	}
}
